package com.sudworth.router;

import android.app.Application;
import android.content.Context;
import android.net.Uri;

import androidx.annotation.Keep;

import com.alibaba.android.arouter.facade.Postcard;
import com.alibaba.android.arouter.facade.callback.NavigationCallback;
import com.alibaba.android.arouter.launcher.ARouter;

/**
 * @Author: shalei
 * @Date: 2019-11-14 09:21
 * @Desc: 主要怕ARouter到处写，以后要修改比较麻烦。
 *        这样包装一层，只改当前的实现就好了
 **/
@Keep
public class RouterProxy implements IRouter{

    private RouterProxy() {

    }

    public static void init(Application application) {
        if (BuildConfig.DEBUG) {           // 这两行必须写在init之前，否则这些配置在init过程中将无效
            ARouter.openLog();     // 打印日志
            ARouter.openDebug();   // 开启调试模式(如果在InstantRun模式下运行，必须开启调试模式！线上版本需要关闭,否则有安全风险)
        }
        ARouter.init(application); // 尽可能早，推荐在Application中初始化
    }

    public static Postcard build(String path) {
        return ARouter.getInstance().build(path);
    }

    /**
     * Inject params and services.
     */
    public static void inject(Object thiz) {
        ARouter.getInstance().inject(thiz);
    }

    /**
     * Build the roadmap, draw a postcard.
     *
     * @param path  Where you go.
     * @param group The group of path.
     */
    @Deprecated
    public static Postcard build(String path, String group) {
        return ARouter.getInstance().build(path, group);
    }

    /**
     * Build the roadmap, draw a postcard.
     *
     * @param url the path
     */
    public static Postcard build(Uri url) {
        return ARouter.getInstance().build(url);
    }

    /**
     * Launch the navigation by type
     *
     * @param service interface of service
     * @param <T>     return type
     * @return instance of service
     */
    public static <T> T navigation(Class<? extends T> service) {
        return ARouter.getInstance().navigation(service);
    }

    /**
     * Launch the navigation.
     *
     * @param mContext    .
     * @param postcard    .
     * @param requestCode Set for startActivityForResult
     * @param callback    cb
     */
    public static Object navigation(Context mContext, Postcard postcard, int requestCode, NavigationCallback callback) {
        return ARouter.getInstance().navigation(mContext, postcard, requestCode, callback);
    }

    /**
     * 只能在debug下使用
     */
    public static void destroy() {
        ARouter.getInstance().destroy();
    }
}
